package com.fxnotes.database.inmemory.repository;

import com.google.inject.Inject;
import com.fxnotes.database.inmemory.InMemoryDatabase;
import com.fxnotes.domain.model.Chapter;
import com.fxnotes.domain.model.Page;
import com.fxnotes.domain.repository.IPageRepository;

public class PageRepository implements IPageRepository {

    private final InMemoryDatabase database;

    @Inject
    public PageRepository(InMemoryDatabase database) {
        this.database = database;
    }

    @Override
    public void add(Chapter chapter, Page page) throws EntityDuplicateException {
        if (chapter.getPages().contains(page)) {
            throw new EntityDuplicateException("Page already exists!");
        }
        chapter.getPages().add(page);
    }

    @Override
    public void updateName(Page page, String name) throws EntityDuplicateException {
        page.setName(name);
    }

    @Override
    public void remove(Chapter chapter, Page page) {
        chapter.getPages().remove(page);
    }
}
